﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VideoFileOrganization.DocumentCleanup
{
    public partial class AddExtensions : Form
    {
        private Global global;
        public AddExtensions(Global global)
        {
            InitializeComponent();
            dgExe.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            this.global = global;
            Frame.ScreenHelper.ShowScreen(this);
        }

        private void AddExtensions_Load(object sender, EventArgs e)
        {
            dgExe.Rows.Clear();
            List<string> result = global.BatchRename.Exes.Except(global.BatchRename.Extensions).ToList();
            foreach (string ex in result)
            {
                dgExe.Rows.Add();
                int row = dgExe.RowCount - 1;
                dgExe.Rows[row].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
                dgExe.Rows[row].Cells[0].Value = true;
                dgExe.Rows[row].Cells[1].Value = ex;
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            for(int i=0; i<dgExe.RowCount; i++)
            {
                object cellValue = dgExe.Rows[i].Cells[0].Value;
                if (cellValue != null && cellValue.Equals(true))
                {
                    global.BatchRename.Extensions.Add(dgExe.Rows[i].Cells[1].Value.ToString());
                }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
